package es.ucm.fdi.pe.practica1.interfaz1;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JComponent;
import javax.swing.JCheckBox;

import es.ucm.fdi.pe.practica1.interfaz1.ConfigPanel.SimpleOption;

/**
 * A simple boolean option
 * @author mfreire
 */
public class BooleanOption<T> extends SimpleOption<T> {
	public BooleanOption(String nombre, String tooltip, String fieldName) {
		super(nombre, tooltip, fieldName);
	}		
	public BooleanOption(String nombre, String tooltip) {
		this(nombre, tooltip, null);
	}		
	@Override
	public JComponent getControlComponent() {
		JCheckBox jtf = new JCheckBox(this.label);
		jtf.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) { cp.rootPanel.update(); }
		});
		return jtf;
	}
	@Override
	protected void writeControl(Object o) {
		((JCheckBox)control).setSelected((Boolean) o);
	}
	@Override
	protected Object readControl() {
		return ((JCheckBox)control).isSelected();
	}
	@Override
	protected boolean isValid(Object v) {
		return true;
	}
}
